package com.sxfq.loansupermarket.backsystem.modular.basicData.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.util.CommUtils;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.dao.OutpatientManagementDao;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.OutpatientManagementInfo;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.SearchOutpatientManagementInfo;
import com.sxfq.loansupermarket.backsystem.modular.basicData.service.IOutpatientManagementService;
import com.sxfq.loansupermarket.backsystem.modular.system.transfer.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class OutpatientManagementServiceImpl implements IOutpatientManagementService {

    @Autowired
    private OutpatientManagementDao dao;

    @Autowired
    private SqlMapper sqlMapper;

    @Override
    public List<OutpatientManagementInfo> selectPageListByQueryGetMap(Page<OutpatientManagementInfo> page, SearchOutpatientManagementInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getOutpatientName())) {
            params.put("outpatientName", searchInfo.getOutpatientName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getAbbreviation())) {
            params.put("abbreviation", searchInfo.getAbbreviation());
        }
        return dao.getQueryPage(page, params);
    }

    public OutpatientManagementInfo selectOneById(String outpatientManagementId) {
        String sql = "select * from outpatient_management_info where id= '" + outpatientManagementId + "'";
        OutpatientManagementInfo info = sqlMapper.selectOne(sql, OutpatientManagementInfo.class);
        return info;
    }

    public int insert(OutpatientManagementInfo info) {
        String sql = "INSERT INTO `outpatient_management_info` (`outpatient_name` , `remarks`, `num`, `abbreviation`) VALUES" +
                "('" + info.getOutpatientName().trim() + "' ,'" + info.getRemarks().trim() + "'," + info.getNum() + ",'" + info.getAbbreviation().trim() + "');";
        return sqlMapper.insert(sql);
    }


    @Transactional
    public void delete(String id) {
        String sql = "delete from outpatient_management_info  where id = '" + id + "'";
        sqlMapper.delete(sql);
    }

    public int update(OutpatientManagementInfo info) {
        return dao.updateById(info);
    }

    public List<Map<String, Object>> list() {
//        String sql = "select id, outpatient_name,abbreviation from outpatient_management_info order by  num asc;";
        String sql = "select id, simplename, fullname from dept where 1=1  and simplename like CONCAT('%','店','%');";
        return sqlMapper.selectList(sql);
    }

    public List<Map<String, Object>> lists(String userName) {
        String selectsql = "select * from user a where account='" + userName + "'";
        UserDto userDto = sqlMapper.selectOne(selectsql, UserDto.class);
        String sql = "";
        if (userDto.getDeptid() != 24) {
            sql = "select id, simplename, fullname from dept where 1=1  and simplename like CONCAT('%','店','%')" +
//                    " and id like CONCAT('%','" + userDto.getDeptid() + "','%') ;";
                    " and id ='" + userDto.getDeptid() + "' ;";
        } else {
            sql = "select id, simplename, fullname from dept where 1=1  and simplename like CONCAT('%','店','%');";
        }
        return sqlMapper.selectList(sql);
    }
}
